﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using Maticsoft.Common;

namespace Admin.WorkFlow.FormTable.PromiseSubContract
{
    public partial class PromiseSubContract_Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDDLProject();
                BindDDLOrganize();
                if (Request.Params["id"] != null && Request.Params["id"].ToString() != "")
                    BindInfo(ChinaSoft.Common.Input.SetInt(Request.Params["id"]));
            }
        }
      /// <summary>
        /// 绑定项目信息
        /// </summary>
        private void BindDDLProject()
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_ProjectInfo bllProject = new ChinaSoft.BLL.BLL_tb_MidSoft_ProjectInfo();
            DataSet ds = bllProject.GetAllList();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ddlProjectName.DataSource = ds;
                ddlProjectName.DataTextField = "ProjectName";
                ddlProjectName.DataValueField = "ProjectInfoId";
                ddlProjectName.DataBind();
                ddlProjectName.Items.Insert(0, "");
            }
        }
        /// <summary>
        /// 绑定合作（分包）单位
        /// </summary>
        private void BindDDLOrganize()
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Organize bllOrganzie = new ChinaSoft.BLL.BLL_tb_MidSoft_Organize();
            DataSet ds = bllOrganzie.GetAllList();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ddlOrganize.DataSource = ds;
                ddlOrganize.DataTextField = "OrganizeName";
                ddlOrganize.DataValueField = "OrganizeId";
                ddlOrganize.DataBind();
                ddlOrganize.Items.Insert(0, "");
            }
        }

        private void BindInfo(int Id)
        {
            ChinaSoft.Model.Model_tb_MidSoft_PromiseSubContract model = new ChinaSoft.Model.Model_tb_MidSoft_PromiseSubContract();
            ChinaSoft.BLL.BLL_tb_MidSoft_PromiseSubContract bll = new ChinaSoft.BLL.BLL_tb_MidSoft_PromiseSubContract();
            model = bll.GetModel(Id);
            if (model != null)
            {
                ddlProjectName.SelectedValue = model.ProjectInfoId.ToString();
                ddlOrganize.SelectedValue = model.OrganizeId.ToString();
                txtStage.Text = model.Stage;
                txtContractName.Text = model.ContractName;
                txtMobile.Text = ChinaSoft.Common.Input.SetString(model.Mobile);
                txtReason.Text = ChinaSoft.Common.Input.SetString(model.Reason);
            }
        }
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ChinaSoft.Model.Model_tb_MidSoft_PromiseSubContract model = new ChinaSoft.Model.Model_tb_MidSoft_PromiseSubContract();
            ChinaSoft.BLL.BLL_tb_MidSoft_PromiseSubContract bll = new ChinaSoft.BLL.BLL_tb_MidSoft_PromiseSubContract();
            model = bll.GetModel(ChinaSoft.Common.Input.SetInt(Request.Params["id"]));
            model.ProjectInfoId = ChinaSoft.Common.Input.SetInt(ddlProjectName.SelectedValue);
            model.PmFlowId = ChinaSoft.Common.Input.SetInt(Request.Params["PmFlowId"]);
            model.OrganizeId = ChinaSoft.Common.Input.SetInt(ddlOrganize.SelectedValue);
            model.ContractName = txtContractName.Text.Trim();
            model.Mobile = txtMobile.Text.Trim();
            model.Reason = txtReason.Text.Trim();
            bll.Update(model);
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}